#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
 
int main()
{
    long long q = 0;
    cin >> q;
    while(q--)
    {
        long long tmp = 0;
        cin >> tmp;
        string str = to_string(tmp);
        bool flag = false;
        sort(str.begin(), str.end());
        do
        {
            int x = atoi(str.c_str());
            if(x % 2 == 0)
            {
                cout << x << endl;
                flag = true;
                break;
            }
        }while (next_permutation(str.begin(), str.end()));
        if(flag == false)
            cout << -1 << endl;
    }
    return 0;
}